$(function(){

    //取出当前的URL
    function GetUrl(){
        var ContrStr = window.location.href;
        var NewContrStr = ContrStr.split('/');
        //alert(NewContrStr);
        var str = '';
       for(var i = 0; i < NewContrStr.length; i++){

         
         if(NewContrStr[i] == 'index' || NewContrStr[i] == 'admin'){
            str += (NewContrStr[i] + '/');
                return str;
         }
         str += (NewContrStr[i] + '/');
       }
    }
    
    var AjaxUrl = GetUrl();
    // alert(1);
    //AJAX发送函数 提现同意
    function getWeather(Action,controller,withDraw_id,element_name,AjaxUrl,userid){
        //alert('ajaxSend...');
        var aa = AjaxUrl + '' + controller +"/"+Action;
        alert(aa);
        $.ajax({  

            datatype:"json",
                    type : "GET",  //提交方式  
                     // url : "http://localhost/AdminFrame/public/admin/" + controller +"/"+Action+controller,//路径 
                     url : AjaxUrl + '' + controller +"/"+Action,//路径 
                     //url : "http://localhost/AdminFrame/public/admin/Bill/withDrawSET",//路径 
                    //url : "http://localhost/AdminFrame/public/admin/user/"+Action+"cate",//路径 
                    data : {  
                        
                        "withDraw_id":withDraw_id,
                        "element_name":element_name,
                        "userid" : userid


                    },//数据，这里使用的是Json格式进行传输  
                    success : function(result) {//返回数据根据结果进行相应的处理
                        
                        alert("修改成功");
                        //转成json 字符串
                        var ResultJsonObject = $.parseJSON(result);
                       
                        
                            
                    },
                    error : function(result){
                        alert("修改失败");
                    } 
                }); 
    }
    


    //alert(1);
    //提现审批同意
    $('input[name = agree]').click(function(){
        var sure = confirm('是否同意？')
    if(!sure){
        alert('操作已取消');
        window.location.reload();
        return ;}
        var withDraw_id = $(this).parent().siblings().first().html();

        var Action = "withDrawSET";
        var controller = "Bill";
        var element_name = "agree";
        var test = "1";
        getWeather(Action,controller,withDraw_id,element_name,AjaxUrl,test);
        
         location.reload();

    })
    //提现审批拒绝
    $('input[name = refuse]').click(function(){
        var sure = confirm('是否拒绝？')
    if(!sure){
        alert('操作已取消');
        window.location.reload();
        return ;}
        var withDraw_id = $(this).parent().siblings().first().html();

        var Action = "withDrawFAL";
        var controller = "Bill";
        var element_name = "refuse";
        var test = "1";
        getWeather(Action,controller,withDraw_id,element_name,AjaxUrl,test);
        
         location.reload();
    })

    //充值审批拒绝
    $('input[name = payrefuse]').click(function(){
        var sure = confirm('是否拒绝？')
    if(!sure){
        alert('操作已取消');
        window.location.reload();
        return ;    
    }    
        var withDraw_id = $(this).parent().siblings().first().html();
        var userid = $(this).parent().siblings('input[name="userid"]').val();
        var Action = "payIndexFAL";
        var controller = "Bill";
        var element_name = "payrefuse";
        getWeather(Action,controller,withDraw_id,element_name,AjaxUrl,userid);
        
         location.reload();
    })

    //充值审批同意
    $('input[name = payagree]').click(function(){
        var sure = confirm('是否同意？')
    if(!sure){
        alert('操作已取消');
        window.location.reload();
        return ;    
    }    
        var withDraw_id = $(this).parent().siblings().first().html();
        var userid = $(this).parent().siblings('input[name="userid"]').val();
        alert(userid);
        var Action = "payIndexSET";
        var controller = "Bill";
        var element_name = "payagree";
        getWeather(Action,controller,withDraw_id,element_name,AjaxUrl,userid);
     
        
        location.reload();
    })
})